extends Node

# 升级相关信号
signal upgrade_selected(upgrade_id: String, weapon_name: String)
signal upgrade_applied(upgrade_id: String, weapon_name: String)

# 游戏状态信号
signal game_paused(paused: bool)

# 单例实例
static var instance: Node

func _ready():
	instance = self

# 静态方法，方便其他脚本调用
static func get_instance():
	if not instance:
		# 尝试通过路径查找GameEvent节点
		var scene_tree = Engine.get_main_loop()
		if scene_tree is SceneTree:
			instance = scene_tree.get_first_node_in_group("game_event")
			if not instance:
				# 如果找不到，尝试通过路径查找
				var game_manager = scene_tree.get_first_node_in_group("game_manager")
				if game_manager:
					instance = game_manager.get_node_or_null("GameEvent")
	return instance

static func emit_upgrade_selected(upgrade_id: String, weapon_name: String):
	var inst = get_instance()
	if inst:
		inst.upgrade_selected.emit(upgrade_id, weapon_name)

static func emit_upgrade_applied(upgrade_id: String, weapon_name: String):
	var inst = get_instance()
	if inst:
		inst.upgrade_applied.emit(upgrade_id, weapon_name)

static func emit_game_paused(paused: bool):
	var inst = get_instance()
	if inst:
		inst.game_paused.emit(paused)

# 连接信号的便捷方法
static func connect_upgrade_selected(callable: Callable):
	var inst = get_instance()
	if inst:
		inst.upgrade_selected.connect(callable)

static func connect_upgrade_applied(callable: Callable):
	var inst = get_instance()
	if inst:
		inst.upgrade_applied.connect(callable) 
